<!--
 * Copyright (c) 2013-Now http://jeesite.com All rights reserved.
 * No deletion without permission, or be held responsible to law.
 * @author PR
-->
<template>
  <div>
    <BasicTable @register="registerTable">
      <template #tableTitle>
        <Icon :icon="getTitle.icon" class="m-1 pr-1" />
        <span> {{ getTitle.value }} </span>
      </template>
      <template #toolbar>
        <a-button type="default" @click="handleExport()">
          <Icon icon="ant-design:download-outlined" /> {{ t('导出') }}
        </a-button>
      </template>
      <template #firstColumn="{ record }">
        <a @click="handleForm({ mocode: record.mocode })">
          {{ record.mocode }}
        </a>
      </template>
    </BasicTable>
    <InputForm @register="registerDrawer" @success="handleSuccess" />
  </div>
</template>
<script lang="ts">
  export default defineComponent({
    name: 'ViewsMoRd10ViewWmsMomOrderdelApplyDelList',
  });
</script>
<script lang="ts" setup>
  import { defineComponent } from 'vue';
  import { useI18n } from '/@/hooks/web/useI18n';
  import { useMessage } from '/@/hooks/web/useMessage';
  import { useGlobSetting } from '/@/hooks/setting';
  import { downloadByUrl } from '/@/utils/file/download';
  import { router } from '/@/router';
  import { Icon } from '/@/components/Icon';
  import { BasicTable, BasicColumn, useTable } from '/@/components/Table';
  import { viewWmsMomOrderdelApplyDelDelete, viewWmsMomOrderdelApplyDelListData } from '/@/api/wms/mo/rd10/viewWmsMomOrderdelApplyDel';
  import { useDrawer } from '/@/components/Drawer';
  import { FormProps } from '/@/components/Form';

  const { t } = useI18n('mo.rd10.viewWmsMomOrderdelApplyDel');
  const { showMessage } = useMessage();
  const getTitle = {
    icon: router.currentRoute.value.meta.icon || 'ant-design:book-outlined',
    value: router.currentRoute.value.meta.title || t('订单申请信息管理'),
  };

  const searchForm: FormProps = {
    baseColProps: { lg: 6, md: 8 },
    labelWidth: 90,
    fieldMapToTime: [
      ['ddate', ['ddate_gte', 'ddate_lte']],
    ],
    schemas: [
      {
        label: t('生单单号'),
        field: 'mocode',
        component: 'Input',
      },
      {
        label: t('订单日期'),
        field: 'ddate',
        component: 'RangePicker',
      },
      {
        label: t('部门编码'),
        field: 'mdeptcode',
        component: 'Input',
      },
      {
        label: t('部门名称'),
        field: 'mdeptname',
        component: 'Input',
      },
      {
        label: t('存货编码'),
        field: 'invcode',
        component: 'Input',
      },
      {
        label: t('存货名称'),
        field: 'cinvname',
        component: 'Input',
      },
      {
        label: t('存货规格'),
        field: 'cinvstd',
        component: 'Input',
      },
    ],
  };

  const tableColumns: BasicColumn[] = [
    {
      title: t('生单单号'),
      dataIndex: 'mocode',
      key: 'a.mocode',
      sorter: true,
      width: 230,
      align: 'left',
      slot: 'firstColumn',
    },
     {
      title: t('订单日期'),
      dataIndex: 'ddate',
      key: 'a.ddate',
      sorter: true,
      width: 130,
      align: 'center',
    },
    {
      title: t('部门编码'),
      dataIndex: 'mdeptcode',
      key: 'a.mdeptcode',
      sorter: true,
      width: 130,
      align: 'left',
    },
    {
      title: t('部门名称'),
      dataIndex: 'mdeptname',
      key: 'a.mdeptname',
      sorter: true,
      width: 130,
      align: 'left',
    },
    {
      title: t('存货编码'),
      dataIndex: 'invcode',
      key: 'a.invcode',
      sorter: true,
      width: 130,
      align: 'left',
    },
    {
      title: t('存货名称'),
      dataIndex: 'cinvname',
      key: 'a.cinvname',
      sorter: true,
      width: 130,
      align: 'left',
    },
    {
      title: t('存货规格'),
      dataIndex: 'cinvstd',
      key: 'a.cinvstd',
      sorter: true,
      width: 130,
      align: 'left',
    },
    {
      title: t('ERP计划数'),
      dataIndex: 'qty',
      key: 'a.qty',
      sorter: true,
      width: 130,
      align: 'right',
    },
    {
      title: t('ERP已入库数'),
      dataIndex: 'qualifiedinqty',
      key: 'a.qualifiedinqty',
      sorter: true,
      width: 130,
      align: 'right',
    },
    {
      title: t('WMS已申请数'),
      dataIndex: 'iqty',
      key: 'a.iqty',
      sorter: true,
      width: 130,
      align: 'right',
    },
    {
      title: t('WMS剩余申请数'),
      dataIndex: 'syqty',
      key: 'a.syqty',
      sorter: true,
      width: 130,
      align: 'right',
    },
  ];


  const [registerDrawer, { openDrawer }] = useDrawer();
  const [registerTable, { reload, getForm }] = useTable({
    api: viewWmsMomOrderdelApplyDelListData,
    beforeFetch: (params) => {
      return params;
    },
    columns: tableColumns,
    formConfig: searchForm,
    showTableSetting: true,
    useSearchForm: true,
    canResize: true,
  });

  function handleForm(record: Recordable) {
    openDrawer(true, record);
  }

  async function handleExport() {
    const { ctxAdminPath } = useGlobSetting();
    downloadByUrl({
      url: ctxAdminPath + '/mo/rd10/viewWmsMomOrderdelApplyDel/exportData',
      target: '_self',
    });
  }


  async function handleDelete(record: Recordable) {
    const res = await viewWmsMomOrderdelApplyDelDelete(record);
    showMessage(res.message);
    handleSuccess();
  }

  function handleSuccess() {
    reload();
  }
</script>
